home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-01.zip / 01 / Hity z okladki / Acronis True Image Home 10.0 / ti_d_p_30.exe / AcronisTrueImage.msi / Binary.RegisterComPlusScript < prev    next >
Text File  |  2006-11-28  |  18KB  |  670 lines

  1. 'cscript for registering/unregistering Acronis VSS Provider
  2.  
  3. Option Explicit
  4. Dim ProviderName, ProviderDLL, ProviderDescription
  5. Dim Ok, OnRollback
  6.  
  7. Function VBScriptCA_RollbackUninst()
  8.   Ok = 1
  9.   OnRollback = 1
  10.   WriteToLog "Args passed: "&Session.Property("CustomActionData")
  11.   
  12.   Dim Args
  13.   Args = Split(Session.Property("CustomActionData"), ";")
  14.   
  15.   Dim Count, Dummy
  16.   Count = 0
  17.   WriteToLog "Parameters parsed:"
  18.   For Each Dummy In Args
  19.     Count = Count + 1
  20.     WriteToLog "  "&Dummy
  21.   Next
  22.   
  23.   If Count = 0 Then
  24.     WriteToLog "No parameters were passed"
  25.       VBScriptCA_RollbackUninst = 3
  26.       Exit Function
  27.   End If
  28.   
  29.   If Count > 0 Then
  30.     If Args(0) = "-register" AND Count = 4 Then 
  31.       WriteToLog "Uninstall rollback mode detected.."
  32.       ProviderName = Args(1)
  33.       ProviderDLL = Args(2)
  34.       ProviderDescription = Args(3)
  35.  
  36.       InstallClusterMSDTC
  37.  
  38.       If NOT Ok = 1 Then
  39.         VBScriptCA_RollbackUninst = 1
  40.         Exit Function
  41.       End If            
  42.  
  43.       InstallProvider
  44.           
  45.       Err = 0          
  46.     End If 
  47.   End If
  48.   VBScriptCA_RollbackUninst = 1
  49.   Exit Function
  50. End Function
  51.  
  52. Function VBScriptCA_RollbackInst()
  53.   Ok = 1
  54.   OnRollback = 1
  55.   WriteToLog "Args passed: "&Session.Property("CustomActionData")
  56.   
  57.   Dim Args
  58.   Args = Split(Session.Property("CustomActionData"), ";")
  59.   
  60.   Dim Count, Dummy
  61.   Count = 0
  62.   WriteToLog "Parameters parsed:"
  63.   For Each Dummy In Args
  64.     Count = Count + 1
  65.     WriteToLog "  "&Dummy
  66.   Next
  67.   
  68.   If Count = 0 Then
  69.     WriteToLog "No parameters were passed"
  70.     VBScriptCA_RollbackInst = 1
  71.     Exit Function
  72.   End If
  73.   
  74.   If Count > 0 Then
  75.     If Args(0) = "-unregister" AND Count = 3 Then 
  76.       WriteToLog "Rollback mode detected.."
  77.       ProviderName = Args(1)
  78.       ProviderDLL = Args(2)
  79.           
  80.       UninstallProvider
  81.  
  82.       If NOT Ok = 1 Then
  83.       VBScriptCA_RollbackInst = Ok
  84.       Exit Function
  85.       End If
  86.  
  87.       Dim owsh
  88.       Set owsh = CreateObject("Wscript.Shell")
  89.       owsh.Run("regsvr32.exe /s /u "&ProviderDll)
  90.       
  91.       WriteToLog "Dll unregistered with error code = "&Err
  92.       WriteToLog "Done." 
  93.           
  94.     End If
  95.   End If
  96.   VBScriptCA_RollbackInst = 1
  97.   Exit Function
  98. End Function
  99.  
  100. Function VBScriptCA_Uninstall()
  101.   Ok = 1
  102.   OnRollback = 0
  103.   WriteToLog "Args passed: "&Session.Property("CAUnRegisterComPLus_Acronis_VSS_Provider")
  104.   
  105.   Dim Args
  106.   Args = Split(Session.Property("CAUnRegisterComPLus_Acronis_VSS_Provider"), ";")
  107.   
  108.   Dim Count, Dummy
  109.   Count = 0
  110.   WriteToLog "Parameters parsed:"
  111.   For Each Dummy In Args
  112.     Count = Count + 1
  113.     WriteToLog "  "&Dummy
  114.   Next
  115.   
  116.   If Count = 0 Then
  117.     WriteToLog "No parameters were passed"
  118.     VBScriptCA_Uninstall = 3
  119.     Exit Function
  120.   End If
  121.   
  122.   If Count > 0 Then
  123.     If Args(0) = "-unregister" AND Count = 3 Then 
  124.       WriteToLog "Unregistering mode detected.."
  125.       ProviderName = Args(1)
  126.       ProviderDLL = Args(2)
  127.  
  128.       UninstallProvider
  129.  
  130.       If NOT Ok = 1 Then
  131.         VBScriptCA_Uninstall = Ok
  132.         Exit Function
  133.       End If
  134.           
  135.       Dim owsh
  136.       Set owsh = CreateObject("Wscript.Shell")
  137.       owsh.Run("regsvr32.exe /s /u "&ProviderDll)
  138.       
  139.       WriteToLog "Dll unregistered with error code = "&Err
  140.       WriteToLog "Done." 
  141.     End If
  142.   End If
  143.  
  144.   VBScriptCA_Uninstall = 1
  145.   Exit Function
  146. End Function
  147.  
  148. Function VBScriptCA_Install()
  149.   Ok = 1
  150.   OnRollback = 0
  151.   WriteToLog "Args passed: "&Session.Property("CustomActionData")
  152.   
  153.   Dim Args
  154.   Args = Split(Session.Property("CustomActionData"), ";")
  155.   
  156.   Dim Count, Dummy
  157.   Count = 0
  158.   WriteToLog "Parameters parsed:"
  159.   For Each Dummy In Args
  160.     Count = Count + 1
  161.     WriteToLog "  "&Dummy
  162.   Next
  163.   
  164.   If Count = 0 Then
  165.     WriteToLog "No parameters were passed"
  166.       VBScriptCA_Install = 3
  167.       Exit Function
  168.   End If
  169.   
  170.   If Count > 0 Then
  171.     If Args(0) = "-register" AND Count = 4 Then 
  172.       WriteToLog "Registering mode detected.."
  173.       ProviderName = Args(1)
  174.       ProviderDLL = Args(2)
  175.       ProviderDescription = Args(3)
  176.  
  177.       InstallClusterMSDTC
  178.           
  179.       If NOT Ok = 1 Then
  180.         VBScriptCA_Install = Ok
  181.         Exit Function
  182.       End If            
  183.           
  184.       UninstallProvider
  185.           
  186.       If NOT Ok = 1 Then
  187.         VBScriptCA_Install = Ok
  188.         Exit Function
  189.       End If
  190.           
  191.       Dim owsh
  192.       Set owsh = CreateObject("Wscript.Shell")
  193.       owsh.Run("regsvr32.exe /s /u "&ProviderDll)
  194.       
  195.       WriteToLog "Dll unregistered with error code = "&Err
  196.       WriteToLog "Done." 
  197.           
  198.       InstallProvider
  199.           
  200.       If NOT Ok = 1 Then
  201.         VBScriptCA_Install = Ok
  202.         Exit Function
  203.       End If
  204.           
  205.     End If 
  206.   End If
  207.   VBScriptCA_Install = 1
  208.   Exit Function
  209. End Function
  210.  
  211. '******************************************************************************
  212. ' WriteToLogs the usage
  213. '******************************************************************************
  214. Sub WriteToLogsUsage
  215.   WriteToLog "" 
  216.   WriteToLog "Usage:" 
  217.   WriteToLog "" 
  218.   WriteToLog " 1) Registering a VSS/VDS Provider as a COM+ application:" 
  219.   WriteToLog "      CScript.exe " & Wscript.ScriptName & " -register <Provider_Name> <Provider.DLL>  <Provider_Description>" 
  220.   WriteToLog "" 
  221.   WriteToLog " 2) Unregistering a COM+ application associated with a VSS/VDS provider:" 
  222.   WriteToLog "      CScript.exe " & Wscript.ScriptName & " -unregister <Provider_Name>" 
  223.   WriteToLog "" 
  224. End Sub
  225.  
  226.  
  227. '******************************************************************************
  228. ' Installs the Provider
  229. '******************************************************************************
  230. Sub InstallProvider
  231.   On Error Resume Next
  232.  
  233.   WriteToLog "- Sleep for a second initially."
  234.   Sleep 1000
  235.   If NOT Ok = 1 Then Exit Sub
  236.  
  237.   WriteToLog "Creating a new COM+ application:" 
  238.   WriteToLog "- Creating the catalog object "
  239.   Dim cat
  240.   Set cat = CreateObject("COMAdmin.COMAdminCatalog")     
  241.   CheckError 101
  242.   If NOT Ok = 1 Then Exit Sub
  243.  
  244.   WriteToLog "- Get the Applications collection"
  245.   Dim collApps
  246.   Set collApps = cat.GetCollection("Applications")
  247.   CheckCollectionError 102, cat
  248.   If NOT Ok = 1 Then Exit Sub
  249.  
  250.   WriteToLog "- Populate..." 
  251.   collApps.Populate 
  252.   CheckCollectionError 103, collApps
  253.   If NOT Ok = 1 Then Exit Sub
  254.  
  255.   WriteToLog "- Add new application object" 
  256.   Dim app
  257.   Set app = collApps.Add 
  258.   CheckCollectionError 104, collApps
  259.   If NOT Ok = 1 Then Exit Sub
  260.  
  261.   WriteToLog "- Set app name = " & ProviderName & " "
  262.   app.Value("Name") = ProviderName
  263.   CheckObjectError 105, collApps, app
  264.   If NOT Ok = 1 Then Exit Sub
  265.  
  266.   WriteToLog "- Set app description = " & ProviderDescription & " "
  267.   app.Value("Description") = ProviderDescription 
  268.   CheckObjectError 106, collApps, app
  269.   If NOT Ok = 1 Then Exit Sub
  270.  
  271.   ' Only roles added below are allowed to call in.
  272.   WriteToLog "- Set app access check = true "
  273.   app.Value("ApplicationAccessChecksEnabled") = 1   
  274.   CheckObjectError 107, collApps, app
  275.   If NOT Ok = 1 Then Exit Sub
  276.  
  277.   ' Encrypting communication
  278.   WriteToLog "- Set encrypted COM communication = true "
  279.   app.Value("Authentication") = 6                      
  280.   CheckObjectError 108, collApps, app
  281.   If NOT Ok = 1 Then Exit Sub
  282.  
  283.   ' Secure references
  284.   WriteToLog "- Set secure references = true "
  285.   app.Value("AuthenticationCapability") = 2         
  286.   CheckObjectError 109, collApps, app
  287.   If NOT Ok = 1 Then Exit Sub
  288.  
  289.   ' Do not allow impersonation
  290.   WriteToLog "- Set impersonation = false "
  291.   app.Value("ImpersonationLevel") = 2
  292.   CheckObjectError 110, collApps, app
  293.   If NOT Ok = 1 Then Exit Sub
  294.  
  295.   WriteToLog "- Save changes..."
  296.   collApps.SaveChanges
  297.   CheckCollectionError 111, collApps
  298.   If NOT Ok = 1 Then Exit Sub
  299.  
  300.   WriteToLog "- Create Windows service running as Local System"
  301.   cat.CreateServiceForApplication ProviderName, ProviderName , "SERVICE_AUTO_START", "SERVICE_ERROR_NORMAL", "", ".\localsystem", "", 0
  302.   CheckCollectionError 112, cat
  303.   If NOT Ok = 1 Then
  304.     Ok = 1
  305.     Err = 0
  306.     WriteToLog "- Create Windows service failed."
  307.     WriteToLog "- Sleep for 3 seconds then try again.."
  308.     Sleep 3000
  309.     If NOT Ok = 1 Then Exit Sub
  310.  
  311.     WriteToLog "- Create Windows service running as Local System"
  312.     cat.CreateServiceForApplication ProviderName, ProviderName , "SERVICE_AUTO_START", "SERVICE_ERROR_NORMAL", "", ".\localsystem", "", 0
  313.     CheckCollectionError 112, cat
  314.   End If
  315.   If NOT Ok = 1 Then Exit Sub
  316.  
  317.   WriteToLog "- Add the DLL component"
  318.   cat.InstallComponent ProviderName, ProviderDLL , "", ""
  319.   CheckCollectionError 113, cat
  320.   If NOT Ok = 1 Then Exit Sub
  321.   WriteToLog "Done!"
  322.     
  323.   ' Add the new role for the Local SYSTEM account
  324.  
  325.   WriteToLog "Secure the COM+ application:"
  326.   WriteToLog "- Get roles collection"
  327.   Dim collRoles
  328.   Set collRoles = collApps.GetCollection("Roles", app.Key)
  329.   CheckCollectionError 120, cat
  330.   If NOT Ok = 1 Then Exit Sub
  331.  
  332.   WriteToLog "- Populate..."
  333.   collRoles.Populate
  334.   CheckCollectionError 121, collRoles
  335.   If NOT Ok = 1 Then Exit Sub
  336.  
  337.   WriteToLog "- Add new role"
  338.   Dim role
  339.   Set role = collRoles.Add
  340.   CheckCollectionError 122, collRoles
  341.   If NOT Ok = 1 Then Exit Sub
  342.  
  343.   WriteToLog "- Set name = Administrators "
  344.   role.Value("Name") = "Administrators"
  345.   CheckObjectError 123, collRoles, role
  346.   If NOT Ok = 1 Then Exit Sub
  347.  
  348.   WriteToLog "- Set description = Administrators group "
  349.   role.Value("Description") = "Administrators group"
  350.   CheckObjectError 124, collRoles, role
  351.   If NOT Ok = 1 Then Exit Sub
  352.  
  353.   WriteToLog "- Save changes ..."
  354.   collRoles.SaveChanges
  355.   CheckCollectionError 125, collRoles
  356.   If NOT Ok = 1 Then Exit Sub
  357.     
  358.   '
  359.   ' Add users into role
  360.   '
  361.  
  362.   WriteToLog "Granting user permissions:"
  363.   Dim collUsersInRole
  364.   Set collUsersInRole = collRoles.GetCollection("UsersInRole", role.Key)
  365.   CheckCollectionError 130, collRoles
  366.   If NOT Ok = 1 Then Exit Sub
  367.  
  368.   WriteToLog "- Populate..."
  369.   collUsersInRole.Populate
  370.   CheckCollectionError 131, collUsersInRole
  371.   If NOT Ok = 1 Then Exit Sub
  372.  
  373.   WriteToLog "- Add new user"
  374.   Dim user
  375.   Set user = collUsersInRole.Add
  376.   CheckCollectionError 132, collUsersInRole
  377.   If NOT Ok = 1 Then Exit Sub
  378.  
  379.   WriteToLog "- Searching for the Administrators account using WMI..."
  380.  
  381.   ' Get the Administrators account domain and name
  382.   Dim strQuery
  383.   strQuery = "select * from Win32_Account where SID='S-1-5-32-544' and localAccount=TRUE"
  384.   Dim objSet
  385.   set objSet = GetObject("winmgmts:").ExecQuery(strQuery)
  386.   CheckError 133
  387.   If NOT Ok = 1 Then Exit Sub
  388.  
  389.   Dim obj, Account
  390.   For Each obj In objSet
  391.     Set Account = obj
  392.     Exit For
  393.   Next
  394.  
  395.   WriteToLog "- Set user name = .\" & Account.Name & " "
  396.   user.Value("User") = ".\" & Account.Name
  397.   CheckObjectError 140, collUsersInRole, user
  398.   If NOT Ok = 1 Then Exit Sub
  399.  
  400.   WriteToLog "- Add new user"
  401.   Set user = collUsersInRole.Add
  402.   CheckCollectionError 141, collUsersInRole
  403.   If NOT Ok = 1 Then Exit Sub
  404.  
  405.   WriteToLog "- Set user name = Local SYSTEM "
  406.   user.Value("User") = "SYSTEM"
  407.   CheckObjectError 142, collUsersInRole, user
  408.   If NOT Ok = 1 Then Exit Sub
  409.  
  410.   WriteToLog "- Save changes..."
  411.   collUsersInRole.SaveChanges
  412.   CheckCollectionError 143, collUsersInRole
  413.   If NOT Ok = 1 Then Exit Sub
  414.     
  415.   Set app       = Nothing
  416.   Set cat       = Nothing
  417.   Set role      = Nothing
  418.   Set user      = Nothing
  419.  
  420.   Set collApps  = Nothing
  421.   Set collRoles = Nothing
  422.   Set collUsersInRole = Nothing
  423.  
  424.   set objSet    = Nothing
  425.   set obj       = Nothing
  426.  
  427.   WriteToLog "Done." 
  428.  
  429.   On Error GoTo 0
  430. End Sub
  431.  
  432.  
  433. '******************************************************************************
  434. ' Uninstalls the Provider
  435. '******************************************************************************
  436. Sub UninstallProvider
  437.   On Error Resume Next
  438.  
  439.   Dim cat
  440.   Set cat = CreateObject("COMAdmin.COMAdminCatalog")
  441.   CheckError 201
  442.   If NOT Ok = 1 Then Exit Sub
  443.     
  444.   Dim collApps
  445.   Set collApps = cat.GetCollection("Applications")
  446.   CheckCollectionError 202, cat
  447.   If NOT Ok = 1 Then Exit Sub
  448.  
  449.   collApps.Populate
  450.   CheckCollectionError 203, collApps
  451.   If NOT Ok = 1 Then Exit Sub
  452.     
  453.   Dim numApps
  454.   numApps = collApps.Count
  455.   Dim i
  456.   For i = numApps - 1 To 0 Step -1
  457.     If (StrComp(collApps.Item(i).Value("Name"), ProviderName) = 0) Then
  458.       collApps.Remove(i)
  459.       CheckCollectionError 204, collApps
  460.       If NOT Ok = 1 Then Exit Sub
  461.       WriteToLog "- Application " & ProviderName & " removed!"
  462.     End If
  463.   Next
  464.         
  465.   WriteToLog "- Saving changes..."
  466.   collApps.SaveChanges
  467.   CheckCollectionError 205, collApps
  468.   If NOT Ok = 1 Then Exit Sub
  469.  
  470.   Set collApps = Nothing
  471.   Set cat      = Nothing
  472.  
  473.   WriteToLog "Done." 
  474.  
  475.   On Error GoTo 0
  476. End Sub
  477.  
  478.  
  479.  
  480. '******************************************************************************
  481. ' Sub CheckError
  482. '******************************************************************************
  483. Sub CheckError(exitCode)
  484.   If Err = 0 Then Exit Sub
  485.   Ok = exitCode
  486.   DumpVBScriptError exitCode
  487. End Sub
  488.  
  489.  
  490. '******************************************************************************
  491. ' Sub CheckCollectionError
  492. '******************************************************************************
  493. Sub CheckCollectionError(exitCode, coll)
  494.   If Err = 0 Then Exit Sub
  495.   Ok = exitCode
  496.   DumpVBScriptError exitCode
  497.   DumpComPlusError(coll.GetCollection("ErrorInfo"))
  498. End Sub
  499.  
  500.  
  501. '******************************************************************************
  502. ' Sub CheckObjectError
  503. '******************************************************************************
  504. Sub CheckObjectError(exitCode, coll, object)
  505.   If Err = 0 Then Exit Sub
  506.   Ok = exitCode
  507.   DumpVBScriptError exitCode
  508.   DumpComPlusError(coll.GetCollection("ErrorInfo"))
  509. End Sub
  510.  
  511.  
  512.  
  513. '******************************************************************************
  514. ' Sub DumpVBScriptError
  515. '******************************************************************************
  516. Sub DumpVBScriptError(exitCode)
  517.   WriteToLog vbNewLine & "ERROR:"
  518.   WriteToLog "- Error code: " & Err & " [0x" & Hex(Err) & "]"
  519.   WriteToLog "- Exit code: " & exitCode
  520.   WriteToLog "- Description: " & Err.Description
  521.   WriteToLog "- Source: " & Err.Source
  522.   WriteToLog "- Help file: " & Err.Helpfile
  523.   WriteToLog "- Help context: " & Err.HelpContext
  524. End Sub
  525.  
  526.  
  527. '******************************************************************************
  528. ' Sub DumpComPlusError
  529. '******************************************************************************
  530. Sub DumpComPlusError(errors)
  531.   errors.Populate
  532.   WriteToLog "- COM+ Errors detected: (" & errors.Count & ")"
  533.  
  534.   Dim error
  535.   Dim I
  536.   For I = 0 to errors.Count - 1
  537.     Set error = errors.Item(I)
  538.     WriteToLog "   * (COM+ ERROR " & I & ") on " & error.Value("Name")
  539.     WriteToLog "       ErrorCode: " & error.Value("ErrorCode") & " [0x" & Hex(error.Value("ErrorCode")) & "]"
  540.     WriteToLog "       MajorRef: " & error.Value("MajorRef")
  541.     WriteToLog "       MinorRef: " & error.Value("MinorRef")
  542.   Next
  543. End Sub
  544.  
  545.  
  546.  
  547. '******************************************************************************
  548. ' Sub InstallClusterMSDTC
  549. '******************************************************************************
  550. Sub InstallClusterMSDTC
  551.   On Error Resume Next
  552.  
  553.   Dim cluster, group, oMainGroup, oQuorumRes, oDTC, resource
  554.     
  555.   WriteToLog "Detecting MS Cluster..."
  556.     
  557.   Set cluster = CreateObject("MSCluster.Cluster")
  558.   CheckError 400
  559.   If Err <> 0 Then
  560.     WriteToLog "- Unable to detect MS Cluster"
  561.     Err = 0
  562.     WriteToLog "- Proceeding with normal installation..." 
  563.     Ok = 1
  564.     Exit Sub
  565.   End If
  566.     
  567.   Call cluster.Open("")
  568.   If Err <> 0 Then 
  569.     WriteToLog "- Cluster connection attempted. Exit code: " & Err & " [0x" & Hex(Err) & "]"
  570.     Err = 0
  571.     WriteToLog "- This is not a cluster node" 
  572.     WriteToLog "- Proceeding with normal installation..." 
  573.     Exit Sub
  574.   End If
  575.  
  576.   WriteToLog "- Cluster node detected: " & cluster.Name
  577.     
  578.   ' If MS-DTC is already present, ignore
  579.   For Each group In cluster.ResourceGroups
  580.     For Each resource In group.Resources
  581.       If resource.type.name = "Distributed Transaction Coordinator" Then
  582.         WriteToLog "- An MS DTC resource is already present: " & resource.name
  583.         Exit Sub
  584.       End If 
  585.     Next
  586.   Next 
  587.  
  588.   ' Getting the quorum resource
  589.   Set oQuorumRes = cluster.quorumresource
  590.   CheckError 401
  591.     
  592.   ' Getting the main group 
  593.   Set oMainGroup = oQuorumRes.Group
  594.   CheckError 402
  595.   WriteToLog "- Adding new DTC resource in main group " & oMainGroup.Name
  596.  
  597.   ' Refresh the collection
  598.   oMainGroup.resources.Refresh
  599.   CheckError 405
  600.  
  601.   ' Creating the MS-DTC resource
  602.   WriteToLog "- Creating the new DTC Resource..."
  603.   Set oDTC = oMainGroup.Resources.CreateItem("DTC", "Distributed Transaction Coordinator", 0)
  604.   CheckError 406
  605.     
  606.   WriteToLog "- Adding Network Name Dependancy..."
  607.   for each resource in oMainGroup.resources
  608.     if resource.type.name = "Network Name" then
  609.       oDTC.dependencies.additem( resource)
  610.       CheckError 407
  611.       exit for
  612.     end if
  613.   next
  614.     
  615.   WriteToLog "- Adding Quorum Dependancy..."
  616.   oDTC.dependencies.additem(oQuorumRes)
  617.   CheckError 408
  618.     
  619.   WriteToLog "- Bringing MSDTC Online..."
  620.   call oDTC.online("600")
  621.   CheckError 409
  622.     
  623.   set oDTC = nothing
  624.   set oMainGroup = nothing
  625.   set resource = nothing
  626.   set oQuorumRes = nothing
  627.   set cluster = nothing
  628.  
  629.   On Error GoTo 0
  630. End Sub
  631.  
  632. Sub WriteToLog(message)
  633.   Const msiMessageTypeInfo = &H04000000
  634.   Dim msg, record
  635.   msg = "[CUSTOMACTION]: " + message
  636.   Set record = Session.Installer.CreateRecord(1)
  637.   record.StringData(1) = msg
  638.   record.StringData(0) = "[1]"
  639.   record.FormatText
  640.   Session.Message msiMessageTypeInfo, record
  641. End Sub
  642.  
  643. Sub Sleep(period)
  644.   On Error Resume Next
  645.   Ok = 1
  646.   Dim wo
  647.   Set wo = CreateObject("CASupp.ThreadWait")
  648.   CheckError 1001
  649.  
  650.   If Err <> 0 Then
  651.     WriteToLog "- Unable to create ActiveX object 'CASupp.ThreadWait'"
  652.     Err = 0
  653.     WriteToLog "- Continue immediately" 
  654.     Ok = 1
  655.     Exit Sub
  656.   End If
  657.  
  658.   wo.Wait(period)
  659.   CheckError 1002
  660.  
  661.   If Err <> 0 Then
  662.     WriteToLog "- ThreadWait failed"
  663.     Err = 0
  664.     WriteToLog "- Continue immediately" 
  665.     Ok = 1
  666.     Exit Sub
  667.   End If
  668.  
  669. End Sub
  670.